package com.zyht.bank.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.zyht.wechat.framework.env.WechatEnv;

/**
 * <b>描述：如果没有配置微信信息跳转配置页面</b>	<br/>
 * <b>作者：</b>Bob <br/>
 * <b>修改日期：</b>2017年6月28日 - 下午5:34:46<br/>
 *
 */
public class WechatFilter implements Filter{

	private Logger logger = LoggerFactory.getLogger(getClass());
	
	@Override
	public void init(FilterConfig filterConfig) throws ServletException{
		
	}

	@Override
	public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws IOException,ServletException{
		HttpServletRequest httpRequest = (HttpServletRequest) request;
		String requestUrl = httpRequest.getServletPath();
		if(requestUrl.indexOf("/anon/")!=-1){
			chain.doFilter(httpRequest,response);
			return;
		}
		if(!WechatEnv.isWechatConfigOk()){
			if(logger.isInfoEnabled()){
				logger.info("系统尚未设置微信信息，请尽快配置^._.^");
			}
			request.getRequestDispatcher("/admin/sysuser/toAdd.htm").forward(request,response);
			return;
		}
		chain.doFilter(httpRequest,response);
	}

	@Override
	public void destroy(){

	}

}
